﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>接口测试</title>
    <script type="text/javascript" src="~/Common/js/jquery-1.10.2.min.js"></script>
    <style>
        * {
            margin: 0;
            box-sizing: border-box;
        }

        .-block {
            float: left;
            width: 50%;
        }
        .-block-title {
            background-color:#004b68;
            color:#fff;
        }
        .-block-content {
            width: 100%;
            height: 50vh;
        }
    </style>
</head>
<body style="background-color:#e4dfd6">
    <div style="padding: 1em; background-color:#444;color:#fff;">接口测试</div>
    <div style="width:100%;float:left;padding: 0.5em;">
        <span>/api/</span>
        <input type="text" id="url" value="article/get"/>
        <button id="get_btn">GET请求</button>
        <button id="post_btn">POST请求</button>
    </div>
    <div style="width:100%;float:left;">
        <div class="-block">
            <div class="-block-title">请求参数</div>
            <textarea class="-block-content" id="require" style=""></textarea>
        </div>
        <div class="-block">
            <div class="-block-title">返回结果</div>
            <pre class="-block-content" id="result" style="padding:0.5em;background-color:#89bcd9"></pre>
        </div>
    </div>
</body>
<script type="text/javascript">
    jQuery.ajaxSettings.data = {
        token: "qwertuyiadsfghjk"
    }
    function request(method) {
        var require_json;
        try {
            eval("require_json = " + $("#require").val());
            var url = $("#url").val();
            $[method]("/api/" + url, require_json, function (res) {
                console.log(res);
                $("#result").html(JSON.stringify(res, null, 4));
            });
        } catch (err) {
            $("#result").html(err.message);
        }
    }
    $("#get_btn").click(function () {
        request("get");
    });
    $("#post_btn").click(function () {
        request("post");
    });

    $("#require").val("{\n\t\n\t\"exemption\": 1 // 1免检，0有权限检测\n}");
</script>
</html>
